Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: IBC transfer scenarios #10852

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

test: IBC transfer scenarios #10852

wants to merge 15 commits into from

Conversation

0xpatrickdev
Copy link
Member

closes: #XXXX
refs: #XXXX

Description

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

Upgrade Considerations

Copy link

cloudflare-workers-and-pages bot commented Jan 16, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 41768bf
Status: ✅  Deploy successful!
Preview URL: https://3f0753f9.agoric-sdk.pages.dev
Branch Preview URL: https://pc-ibc-xfer-test.agoric-sdk.pages.dev

View logs

@0xpatrickdev 0xpatrickdev force-pushed the pc/ibc-xfer-test branch 2 times, most recently from 21dbe29 to 014071b Compare January 21, 2025 17:23
@michaelfig michaelfig changed the title test: ibc transfer scenarios test: IBC transfer scenarios Jan 23, 2025
@michaelfig michaelfig self-assigned this Jan 23, 2025
@michaelfig michaelfig added the force:integration Force integration tests to run on PR label Jan 23, 2025
Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm confusing myself on which hook does what. Do we have a flow diagram somewhere?

Comment on lines 170 to 187
func (k Keeper) PacketStore(ctx sdk.Context, ourOrigin types.PacketOrigin, ourPort string, ourChannel string, sequence uint64) (storetypes.KVStore, []byte) {
key := fmt.Sprintf("%s/%s/%s/%v", ourOrigin, ourPort, ourChannel, sequence)
packetKey := []byte(key)
return prefix.NewStore(ctx.KVStore(k.key), []byte(packetDataStoreKeyPrefix)), packetKey
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a reference to https://github.com/agoric-labs/ibc-go/blob/v6.3.1-alpha.agoric.2/modules/core/24-host/keys.go#L183-L187 but mention we need to support both directions (hence the extra origin)?

Btw I like the paths used by IBC better because it denotes what each path element is in the name

originalData/{src|dst}/ports/{ourPort}/channel/{ourChannel}/sequences/{sequence}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if StorePacketData && !bytes.Equal(strippedPacket.GetData(), packet.GetData()) {
packetStore, packetKey := k.PacketStoreFromOrigin(ctx, types.PacketSrc, packet)
if !packetStore.Has(packetKey) {
packetStore.Set(packetKey, packet.GetData())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we remembering the packet data when receiving an ack? Shouldn't we assert we had saved packet data if we rewrote the packet, and delete instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, your suggestion is correct.

origPacket := packet
packetStore, packetKey := k.PacketStoreFromOrigin(ctx, types.PacketSrc, packet)
if packetStore.Has(packetKey) {
origPacket.Data = packetStore.Get(packetKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, why do we need to restore the original packet's data? Wouldn't a received timeout packet contain the original packet data in the first place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I've updated this to be the same logic as InterceptOnAckPacket above.

packet.GetDestPort(), packet.GetDestChannel(),
timeout, packet.GetTimeoutTimestamp(),
)
packetStore, packetKey := k.PacketStoreFromOrigin(ctx, types.PacketSrc, packet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're writing an ack, wouldn't we be the destination / receiver? Why are we using a src origin here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it should be PacketDst.

@mhofman mhofman self-requested a review January 23, 2025 06:44
@michaelfig michaelfig marked this pull request as ready for review January 27, 2025 05:27
@michaelfig michaelfig requested a review from a team as a code owner January 27, 2025 05:27
@michaelfig michaelfig requested review from mhofman and removed request for mhofman January 27, 2025 16:12
@michaelfig
Copy link
Member

I think I'm confusing myself on which hook does what. Do we have a flow diagram somewhere?

There is some descriptive text in https://github.com/Agoric/agoric-sdk/pull/10852/files#diff-9f5147516ace799597d78cf5abf1f9d93de4304489b31628b02bc471143c4b84L13 that may help.

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing, especially the tests, but I'm still not sure I understand the order of hooks invocation, especially in the case of ack received for sent ibc packets.

Comment on lines +258 to +260
if StorePacketData && !bytes.Equal(strippedPacket.GetData(), packet.GetData()) {
packetStore, packetKey := k.PacketStoreFromOrigin(ctx, types.PacketSrc, packet)
if packetStore.Has(packetKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this handles the case where stripped packet != packet && store.has(packet).

We have 3 other cases:

  • store.has(packet) && stripped packet == packet. This arguably shouldn't happen, but I don't see a reason to not delete the stored data (if it matches the packet)?
  • stripped packet != packet && !store.has(packet). Could this happen? Wouldn't IBC guarantee that we only see an ack only once for packet we actually sent? Even in the case of timeout. If true, is it worth asserting this is an unexpected packet or just trust IBC that this will never happen?
  • stripped packet == packet && !store.has(packet). This is the normal case where the packet has not be modified and we have nothing to do.

@@ -180,6 +297,18 @@ func (k Keeper) InterceptOnTimeoutPacket(
if err != nil {
return err
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is specific to timeout packets received from a relayer. Is there ever a case where the local IBC logic generates a timeout when it receives an update client past the timeout (after verifying the remote chain didn't include the sent packet in its state)

Comment on lines +345 to +349
packetStore, packetKey := k.PacketStoreFromOrigin(ctx, types.PacketDst, packet)
if packetStore.Has(packetKey) {
origPacket.Data = packetStore.Get(packetKey)
packetStore.Delete(packetKey)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this relate to the deletion done in func (i4 *ics4Wrapper) WriteAcknowledgement ?

Is there a case where we may have an async ack that no longer has the original data saved?

@@ -186,6 +186,6 @@ const queryAccountBalance = test.macro({
test.serial(queryAccountBalances, 'osmosis');
test.serial(queryAccountBalances, 'cosmoshub');
test.serial(queryAccountBalances, 'agoric');
test.serial(queryAccountBalance, 'osmosis');
test.serial.failing(queryAccountBalance, 'osmosis');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these failing now?

@mhofman mhofman requested review from michaelfig and mhofman January 27, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
force:integration Force integration tests to run on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants